<?php

class CommentModel extends RelationModel
{
	public $_link = array (

      'user_id' => array(   
 					'mapping_type'=>BELONGS_TO, 
                    'class_name'=>'user', 
                    'foreign_key'=>'user_id', 
                    'mapping_name'=>'user',
                   )       
	);
	
	public function addComment($book_id, $user_id, $content) {
		$comment['user_id'] = $user_id;
		$comment['book_id'] = $book_id;
		$comment['content'] = $content;
		$comment['create_time'] = time();
		$this->add($comment);
	}
	
	
	public function getByBookId($book_id) {
		$condition['book_id'] = $book_id;
		$comments = $this->where($condition)->relation(true)->select();
		return $comments;
	}
}

?>